package com.ysh.mapper;

import com.ysh.domain.City;
import com.ysh.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
/*
    持久层接口
 */
public interface UserMapper {
    // 查询所有用户信息
    @Select("select * from user")
    @Results(id="userMap",value={
            @Result(id=true,column = "id", property = "id"),
            @Result(property = "city", javaType = City.class, column = "cid",
            one = @One(select = "com.ysh.mapper.CityMapper.findById"))
    })
    List<User> findAll();


    // 添加用户功能
    @Insert("insert into user values(#{id},#{name},#{gender},#{age},#{address},#{qq},#{email})")
    int addUser(User user);

    // 删除功能
    // @Delete("delete from user where id=#{uid}")  xml配置动态SQL
    void deleteByIds(String[] uids);

    // 根据id查询
    @Select("select * from user where id=#{uid}")
    @ResultMap("userMap")
    User findById(String uid);

    // 修改
    @Update("update user set gender=#{gender},age=#{age},address=#{address},qq=#{qq} where id=#{id}")
    void updateById(User user);
}
